Typical HAL HRTIM use cases for migration

This section provides information about typical HAL HRTIM use cases for migration.

The following table highlights some key differences and equivalences between the HAL1 and HAL2 used in the use cases below.

Function

HAL1

HAL2

Time Base Configuration

HAL_HRTIM_TimeBaseConfig() Configures the time base unit of a timer.

HAL_HRTIM_TIM_SetConfig() Configures only the necessary fields; other fields use default values.

Timer Configuration

HAL_HRTIM_WaveformTimerConfig() Configures the entire timer waveform parameters in a single call by passing a fully populated structure.

Split into multiple focused configuration functions; configure only the needed fields, with others taking default values internally.

Output Configuration

HAL_HRTIM_WaveformOutputConfig() Configures output behavior such as set/reset sources, polarity, idle and fault levels, burst mode, and chopper mode in one call.

Functionality split into multiple APIs for modularity and clarity; only the needed configuration functions are called.

Compare Configuration

HAL_HRTIM_WaveformCompareConfig() Configures compare unit, including compare value and auto-delayed mode, in a single function.

Split into separate APIs to set compare value and configure auto-delayed mode independently; only required APIs are used.

Output Enable

HAL_HRTIM_WaveformOutputStart() Enables timer outputs.

HAL_HRTIM_OUT_Enable() Separates output enabling from configuration for clearer semantics.

Timer Start (Polling, Interrupt, DMA)

HAL_HRTIM_WaveformCountStart(), HAL_HRTIM_WaveformCountStart_IT(), HAL_HRTIM_WaveformCountStart_DMA() Starts the timer counter in polling, interrupt, or DMA mode.

HAL_HRTIM_TIM_Start(),

HAL_HRTIM_TIM_Start_IT(),

HAL_HRTIM_TIM_Start_DMA()

More explicit and descriptive function names for starting the timer counter in polling, interrupt, and DMA modes.


Use case: Arbitrary waveform generation

Sequence diagram

@startuml
participant "User Application" as App
participant "HAL HRTIM" as Driver

group HRTIM Initialization
App -[hidden]>Driver
end

group Timer D configuration

App->Driver : HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, &sConfig_time_base);
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D,&sConfig_timerD);
Driver --> App : HAL_OK

App->Driver : \n HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_1, &sConfig_compare);
Driver --> App : HAL_OK

App->Driver : \n HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_2, &sConfig_compare);
Driver --> App : HAL_OK

App->Driver : \n HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_3, &sConfig_compare);
Driver --> App : HAL_OK

App->Driver : HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD1, &sConfig_output_config)
Driver --> App : HAL_OK

App->Driver : HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD2, &sConfig_output_config)
Driver --> App : HAL_OK
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.

end

group Start Signal generation

App -> Driver : HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, (HRTIM_OUTPUT_TD1 | HRTIM_OUTPUT_TD2))
Driver --> App : HAL_OK

App -> Driver : HAL_HRTIM_WaveformCountStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_D)
Driver --> App : HAL_OK

end

@enduml

Code snippet

HAL1

HAL2

Usage

 HRTIM_HandleTypeDef                 hhrtim;

 HRTIM_TimeBaseCfgTypeDef            sConfig_time_base;
 HRTIM_TimerCfgTypeDef               sConfig_timerD;
 HRTIM_OutputCfgTypeDef              sConfig_output_config;
 HRTIM_CompareCfgTypeDef             sConfig_compare;

 hhrtim1.Instance = HRTIM1;
 hhrtim1.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
 hhrtim1.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
 HAL_HRTIM_Init(&hhrtim);

/* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin*/
 .................
 ................

 sConfig_time_base.Period = 0x2000;
 sConfig_time_base.RepetitionCounter = 0x00;
 sConfig_time_base.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV4;
 sConfig_time_base.Mode = HRTIM_MODE_CONTINUOUS;
 HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, &sConfig_time_base);

 sConfig_timerD.InterruptRequests = HRTIM_MASTER_IT_NONE;
 sConfig_timerD.DMARequests = HRTIM_MASTER_DMA_NONE;
 sConfig_timerD.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
 sConfig_timerD.InterleavedMode = HRTIM_INTERLEAVED_MODE_DISABLED;
 sConfig_timerD.StartOnSync = HRTIM_SYNCSTART_DISABLED;
 sConfig_timerD.ResetOnSync = HRTIM_SYNCRESET_DISABLED;
 sConfig_timerD.DACSynchro = HRTIM_DACSYNC_NONE;
 sConfig_timerD.PreloadEnable = HRTIM_PRELOAD_ENABLED;
 sConfig_timerD.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
 sConfig_timerD.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
 sConfig_timerD.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
 sConfig_timerD.ReSyncUpdate = HRTIM_TIMERESYNC_UPDATE_UNCONDITIONAL;
 HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, &sConfig_timerD);

/* Set compare register 1 in Timer D */
sConfig_compare.CompareValue = 0x10;
HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_1, &sConfig_compare);

/* Set compare register 2 in Timer D */
sConfig_compare.CompareValue = 0x20;
HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_2, &sConfig_compare);

/* Set compare register 3 in Timer D */
sConfig_compare.CompareValue = 0x30;
HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_3, &sConfig_compare);

 sConfig_output_config.Polarity = HRTIM_OUTPUTPOLARITY_HIGH;
 sConfig_output_config.IdleLevel = HRTIM_OUTPUTIDLELEVEL_INACTIVE;
 sConfig_output_config.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
 sConfig_output_config.SetSource = HRTIM_OUTPUTSET_TIMPER | HRTIM_OUTPUTSET_TIMCMP1 | HRTIM_OUTPUTSET_TIMCMP2 ;
 sConfig_output_config.ResetSource = HRTIM_OUTPUTRESET_TIMPER | HRTIM_OUTPUTRESET_TIMCMP1 | HRTIM_OUTPUTRESET_TIMCMP2;
 HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD1, &sConfig_output_config);

 sConfig_output_config.SetSource = HRTIM_OUTPUTSET_TIMPER | HRTIM_OUTPUTSET_TIMCMP2 ;
 sConfig_output_config.ResetSource =  HRTIM_OUTPUTRESET_TIMCMP1 | HRTIM_OUTPUTRESET_TIMCMP2;
 HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD2, &sConfig_output_config);

 /* Enable HRTIM's outputs TD1 and TD2 */
 HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TD1 | HRTIM_OUTPUT_TD2);

 /* Start HRTIM TIMER D in polling mode*/
 HAL_HRTIM_WaveformCountStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_D);
 hal_hrtim_handle_t                 hhrtim;

 hal_hrtim_timer_config_t           timer_d_config;
 hal_hrtim_output_config_t          output_config;

HAL_HRTIM_Init(&hhrtim1, HAL_HRTIM1);

/* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin*/
 .................
 ................

timer_d_config.period = 0x2000;
timer_d_config.repetition = 0x00;
timer_d_config.prescaler = HAL_HRTIM_TIM_PRESCALER_DIV4;
timer_d_config.operating_mode = HAL_HRTIM_TIM_MODE_CONTINUOUS;
HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMD,  &timer_d_config);

HAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_UPDATE_SOURCE_REPETITION);
HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_TIMD);

/* Set compare register 1 in Timer D */
HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_1, 0x10);

/* Set compare register 2 in Timer D */
HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_2, 0x20);

/* Set compare register 3 in Timer D */
HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_3, 0x30);

 output_config.set = HAL_HRTIM_OUT_SET_PERIOD | HAL_HRTIM_OUT_SET_CMP1 | HAL_HRTIM_OUT_SET_CMP2;
 output_config.reset = HAL_HRTIM_OUT_RESET_PERIOD | HAL_HRTIM_OUT_RESET_CMP1 | HAL_HRTIM_OUT_RESET_CMP2;
 output_config.polarity = HAL_HRTIM_OUTPUT_ACTIVE_HIGH;
 output_config.idle_level = HAL_HRTIM_OUTPUT_IDLE_INACTIVE;
 output_config.fault_level = HAL_HRTIM_OUTPUT_FAULT_NONE;
 HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD1, &output_config);

 output_config.set = HAL_HRTIM_OUT_SET_PERIOD |HAL_HRTIM_OUT_SET_CMP2;
 output_config.reset = HAL_HRTIM_OUT_RESET_CMP1 | HAL_HRTIM_OUT_RESET_CMP2;
 HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD2, &output_config);

 /* Enable HRTIM's outputs CHD1 and CHD2 */
 HAL_HRTIM_OUT_Enable(&hhrtim, (HAL_HRTIM_CHD1 | HAL_HRTIM_CHD2));

 /* Start HRTIM's TIMER D in polling mode */
 HAL_HRTIM_TIM_Start(&hhrtim,  HAL_HRTIM_TIMD);

Key changes

  • HAL2 uses HAL_HRTIM_TIM_SetConfig() with default values for non-configured fields.

  • HAL2 sets compare values via HAL_HRTIM_TIM_SetCompareValue() instead of waveform compare configuration.

  • HAL2 splits output configuration (HAL_HRTIM_OUT_SetConfig()) from output enabling (HAL_HRTIM_OUT_Enable()) and timer start (HAL_HRTIM_TIM_Start()).


Use case: Generate PWM waveform with interrupts

Sequence diagram

@startuml
' To add a number by line
'autonumber
' Fix order of each column

participant "User Application" as App
participant "HAL HRTIM" as Driver

group HRTIM Initialization
App -[hidden]>Driver
end

group Timer A configuration

App -> Driver: HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_timerA)
Driver -> Driver: Timer A interrupt mask is stored\ninto the HRTIM handle
Driver --> App : HAL_OK

App -> Driver: HAL_HRTIM_DeadTimeConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &dead_time_config)
Driver -> Driver: Timer A interrupt mask is stored\ninto the HRTIM handle
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, &sConfig_compare);
Driver --> App : HAL_OK

App->Driver : HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_time_base)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &sConfig_output_config);
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.
Driver --> App : HAL_OK

end

group Start Signal generation (interrupt mode)

 App -> Driver : HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1);
 Driver --> App : HAL_OK

 App -> Driver : HAL_HRTIM_WaveformCountStart_IT(&hhrtim, HRTIM_TIMERINDEX_TIMER_A)
 Driver --> App : HAL_OK

end

@enduml

Code snippet

HAL1

HAL2

Usage

 HRTIM_HandleTypeDef                 hhrtim;

 HRTIM_TimeBaseCfgTypeDef            sConfig_time_base;
 HRTIM_TimerCfgTypeDef               sConfig_timerA;
 HRTIM_OutputCfgTypeDef              sConfig_output_config;
 HRTIM_CompareCfgTypeDef             sConfig_compare;
 HRTIM_DeadTimeCfgTypeDef            dead_time_config;

 hhrtim1.Instance = HRTIM1;
 hhrtim1.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
 hhrtim1.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
 HAL_HRTIM_Init(&hhrtim);

/* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin*/
 .................
 ................

 sConfig_time_base.Period = 0x2000;
 sConfig_time_base.RepetitionCounter = 0x00;
 sConfig_time_base.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV4;
 sConfig_time_base.Mode = HRTIM_MODE_CONTINUOUS;
 HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_time_base);

 sConfig_timerA.InterruptRequests = HRTIM_MASTER_IT_MCMP1;
 sConfig_timerA.DMARequests = HRTIM_MASTER_DMA_NONE;
 sConfig_timerA.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
 sConfig_timerA.InterleavedMode = HRTIM_INTERLEAVED_MODE_DISABLED;
 sConfig_timerA.StartOnSync = HRTIM_SYNCSTART_DISABLED;
 sConfig_timerA.ResetOnSync = HRTIM_SYNCRESET_DISABLED;
 sConfig_timerA.DACSynchro = HRTIM_DACSYNC_NONE;
 sConfig_timerA.PreloadEnable = HRTIM_PRELOAD_ENABLED;
 sConfig_timerA.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
 sConfig_timerA.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
 sConfig_timerA.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_ENABLED;
 sConfig_timerA.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
 sConfig_timerA.ReSyncUpdate = HRTIM_TIMERESYNC_UPDATE_UNCONDITIONAL;
 HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_timerA);

 dead_time_config.RisingValue = 0x5;
 dead_time_config.RisingSign = HRTIM_TIMDEADTIME_RISINGSIGN_POSITIVE;
 HAL_HRTIM_DeadTimeConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &dead_time_config);

 dead_time_config.FallingValue = 0x3;
 dead_time_config.FallingSign = HRTIM_TIMDEADTIME_FALLINGSIGN_POSITIVE;
 HAL_HRTIM_DeadTimeConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &dead_time_config);

 /* Set compare register 1 in Timer A */
 sConfig_compare.CompareValue = 0x20;
 HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, &sConfig_compare);

 sConfig_output_config.Polarity = HRTIM_OUTPUTPOLARITY_HIGH;
 sConfig_output_config.IdleLevel = HRTIM_OUTPUTIDLELEVEL_INACTIVE;
 sConfig_output_config.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
 sConfig_output_config.SetSource = HRTIM_OUTPUTSET_TIMCMP1  ;
 sConfig_output_config.ResetSource = HRTIM_OUTPUTRESET_TIMPER ;
 HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &sConfig_output_config);

 /* Enable HRTIM's outputs TA1 */
 HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TA1);

 /* Start HRTIM TIMER A in interrupt mode */
 HAL_HRTIM_WaveformCountStart_IT(&hhrtim, HRTIM_TIMERINDEX_TIMER_A);
 hal_hrtim_handle_t                 hhrtim;

 hal_hrtim_timer_config_t           timer_a_config;
 hal_hrtim_output_config_t          output_config;
 hal_hrtim_deadtime_config_t        dead_time_config;

HAL_HRTIM_Init(&hhrtim, HAL_HRTIM1);

/* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin*/
 .................
 ................

timer_a_config.period = 0x2000;
timer_a_config.repetition = 0x00;
timer_a_config.prescaler = HAL_HRTIM_TIM_PRESCALER_DIV4;
timer_a_config.operating_mode = HAL_HRTIM_TIM_MODE_CONTINUOUS;
HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMA,  &timer_a_config);

HAL_HRTIM_SetConfigInterrupts(&hhrtim, HAL_HRTIM_IT_TIMA, HAL_HRTIM_OPT_IT_CMP1);
HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_TIMA);
HAL_HRTIM_TIM_EnableDeadtime(&hhrtim, HAL_HRTIM_TIMA);
HAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_UPDATE_SOURCE_REPETITION);

dead_time_config.value = 0x5;
dead_time_config.sign = HAL_HRTIM_DEADTIME_POSITIVE;
HAL_HRTIM_TIM_SetConfigDeadtime(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_DEADTIME_RISING, &dead_time_config);

dead_time_config.value = 0x3;
HAL_HRTIM_TIM_SetConfigDeadtime(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_DEADTIME_FALLING, &dead_time_config);

/* Set compare register 1 in Timer A */
HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_COMPARE_UNIT_1, 0x20);

 output_config.set = HAL_HRTIM_OUT_SET_CMP1;
 output_config.reset = HAL_HRTIM_OUT_RESET_PERIOD ;
 output_config.polarity = HAL_HRTIM_OUTPUT_ACTIVE_HIGH;
 output_config.idle_level = HAL_HRTIM_OUTPUT_IDLE_INACTIVE;
 output_config.fault_level = HAL_HRTIM_OUTPUT_FAULT_NONE;
 HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHA1, &output_config);

 /* Enable HRTIM's outputs CHA1 */
 HAL_HRTIM_OUT_Enable(&hhrtim, HAL_HRTIM_CHA1);

 /* Start HRTIM TIMER A in interrupt mode */
 HAL_HRTIM_TIM_Start_IT(&hhrtim,  HAL_HRTIM_TIMA);

Key changes

  • HAL2 configures interrupts explicitly (HAL_HRTIM_SetConfigInterrupts()) and starts the timer in IT mode with HAL_HRTIM_TIM_Start_IT().

  • HAL2 splits deadtime configuration across dedicated APIs (HAL_HRTIM_TIM_SetConfigDeadtime() / HAL_HRTIM_TIM_EnableDeadtime()).

  • HAL2 separates output configuration (HAL_HRTIM_OUT_SetConfig()) from output enabling (HAL_HRTIM_OUT_Enable()).


Use case: External event capture with DMA

Sequence diagram

@startuml
' To add a number by line
' autonumber
' Fix order of each column

participant "User Application" as App
participant "HAL HRTIM" as Driver
participant "HAL DMA" as DMA

group "HRTIM Initialization"
  App -[hidden]-> Driver
end

group "DMA channel Initialization (Peripheral to Memory)"
  App -> DMA : DMA channel initialization
  App -> Driver : __HAL_LINKDMA(&hhrtim, hdmaTimerA, hdma)
  Driver -> Driver : DMA channel handle associated to Timer A\nis stored into the HRTIM handle
end

group "Timer A configuration"
  note right of App : dma_config must be persistent\n(accessed through the HRTIM handle by\nHAL_HRTIM_WaveformCountStart_DMA function)

  App -> Driver : HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_timerA)
  Driver -> Driver : Pointer to Timer A DMA configuration\nstored into HRTIM handle
  Driver --> App : HAL_OK

  App --> Driver : HAL_HRTIM_EventConfig(&hhrtim, HRTIM_EVENT_3, &event_config)
  Driver --> App : HAL_OK

  App -> Driver : HAL_HRTIM_TimerEventFilteringConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_EVENT_3, &timer_event_config)
  Driver --> App : HAL_OK

  App -> Driver : HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_time_base)
  Driver --> App : HAL_OK

  App -> Driver : HAL_HRTIM_WaveformCaptureConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_CAPTUREUNIT_1, &capture_unit_1_config)
  Driver --> App : HAL_OK
end

group "Timer B configuration"
  App -> Driver : HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, &sConfig_time_base)
  Driver --> App : HAL_OK

  App -> Driver : HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, &sConfig_compare)
  Driver --> App : HAL_OK
end

group "Start input capture (DMA mode)"
  App -> Driver : HAL_HRTIM_WaveformCountStart_DMA(&hhrtim, (HRTIM_TIMERID_TIMER_A | HRTIM_TIMERID_TIMER_B))
  Driver -> Driver : Enable capture 1 DMA request
  Driver -> DMA : Start DMA transfer in interrupt mode
  Driver --> App : HAL_OK
end

@enduml

Code snippet

HAL1

HAL2

Usage

 HRTIM_HandleTypeDef                 hhrtim;

 HRTIM_TimeBaseCfgTypeDef            sConfig_time_base;
 HRTIM_TimerCfgTypeDef               sConfig_timerA;
 HRTIM_EventCfgTypeDef               event_config;
 HRTIM_TimerEventFilteringCfgTypeDef timer_event_config;
 HRTIM_CompareCfgTypeDef             sConfig_compare;

 hhrtim1.Instance = HRTIM1;
 hhrtim1.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
 hhrtim1.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
 HAL_HRTIM_Init(&hhrtim);

/* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin, and link DMA channel handle
to HRTIM TIMER A handle*/
 .................
 ................

 /* Timer A configuration */
 sConfig_timerA.InterruptRequests = HRTIM_TIM_IT_NONE;
 sConfig_timerA.DMARequests = HRTIM_TIM_DMA_CPT1;
 sConfig_timerA.DMASrcAddress = (uint32_t)DMATransferSrc;
 sConfig_timerA.DMADstAddress = (uint32_t)DMATransferDest;
 sConfig_timerA.DMASize = 12;
 sConfig_timerA.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
 sConfig_timerA.InterleavedMode = HRTIM_INTERLEAVED_MODE_DISABLED;
 sConfig_timerA.StartOnSync = HRTIM_SYNCSTART_DISABLED;
 sConfig_timerA.ResetOnSync = HRTIM_SYNCRESET_DISABLED;
 sConfig_timerA.DACSynchro = HRTIM_DACSYNC_NONE;
 sConfig_timerA.PreloadEnable = HRTIM_PRELOAD_DISABLED;
 sConfig_timerA.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
 sConfig_timerA.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
 sConfig_timerA.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_DISABLED;
 sConfig_timerA.RepetitionUpdate = HRTIM_UPDATEONREPETITION_DISABLED;
 sConfig_timerA.ReSyncUpdate = HRTIM_TIMERESYNC_UPDATE_UNCONDITIONAL;
 HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_timerA);

 event_config.Source = HRTIM_EEV6SRC_GPIO;
 event_config.Sensitivity = HRTIM_EVENTSENSITIVITY_RISINGEDGE;
 HAL_HRTIM_EventConfig(&hhrtim, HRTIM_EVENT_3, &event_config)

 timer_event_config.Filter = HRTIM_TIMEVENTFILTER_BLANKINGCMP1;
 timer_event_config.Latch = HRTIM_TIMEVENTLATCH_DISABLED;
 HAL_HRTIM_TimerEventFilteringConfig(&hhrtim,  HRTIM_TIMERINDEX_TIMER_A, HRTIM_EVENT_3, &timer_event_config);

 sConfig_time_base.Period = 0x2000;
 sConfig_time_base.RepetitionCounter = 0x00;
 sConfig_time_base.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV4;
 sConfig_time_base.Mode = HRTIM_MODE_CONTINUOUS;
 HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &sConfig_time_base);

 capture_unit_1_config.Trigger = HRTIM_CAPTURETRIGGER_EEV_3;
 HAL_HRTIM_WaveformCaptureConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_CAPTUREUNIT_1, &capture_unit_1_config);

/* Timer B configuration */
 sConfig_time_base.Period = 0x2000;
 sConfig_time_base.RepetitionCounter = 0x00;
 sConfig_time_base.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV4;
 sConfig_time_base.Mode = HRTIM_MODE_CONTINUOUS;
 HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, &sConfig_time_base);

 /* Set compare register 1 in Timer B */
 sConfig_compare.CompareValue = 0x100;
 HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, &sConfig_compare);

 /* Start HRTIM TIMER A in DMA mode and HRTIM TIMER B in polling mode*/
 HAL_HRTIM_WaveformCountStart_DMA(&hhrtim, HRTIM_TIMERINDEX_TIMER_A | HRTIM_TIMERINDEX_TIMER_B);
  hal_hrtim_handle_t                 hhrtim;

  hal_hrtim_timer_config_t           timer_config;
  hal_hrtim_dma_config_t             dma_config;
  hal_hrtim_eev_config_t             evt3_config;
  hal_hrtim_eev_filter_config_t      evt3_filter;

 HAL_HRTIM_Init(&hhrtim, HAL_HRTIM1);

 /* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin, and link DMA channel handle
 to HRTIM TIMER A handle*/
  .................
  ................

 /* Timer A configuration */
 dma_config.requests = HAL_HRTIM_OPT_DMA_CPT1;
 dma_config.dest_addr = (uint32_t)DMATransferDest;
 dma_config.src_addr = (uint32_t)DMATransferSrc;
 dma_config.size_byte = 12;
 HAL_HRTIM_SetConfigDMA(&hhrtim, HAL_HRTIM_DMA_TIMA,&dma_config);

 /* Configure external events sensitivity */
 evt3_config.source = HAL_HRTIM_EEV3_GPIO;
 evt3_config.sensitivity = HAL_HRTIM_EEV_EDGE_RISING;
 HAL_HRTIM_EEV_SetConfig(&hhrtim, HAL_HRTIM_EEV3, &evt3_config)

 evt3_filter.filter = HAL_HRTIM_BLK_RST_CMP1;
 evt3_filter.notification = HAL_HRTIM_EEV_IMMEDIATE;
 HAL_HRTIM_TIM_SetEventFilter(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_EEV3, &evt3_filter);

 timer_a_config.period = 0x2000;
 timer_a_config.repetition = 0x00;
 timer_a_config.prescaler = HAL_HRTIM_TIM_PRESCALER_DIV4;
 timer_a_config.operating_mode = HAL_HRTIM_TIM_MODE_CONTINUOUS;
 HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMA,  &timer_config);

 HAL_HRTIM_TIM_SetCaptureTrigger(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_CAPTURE_UNIT_1, HAL_HRTIM_EEV3);

/* Timer B configuration */
 timer_b_config.period = 0x2000;
 timer_b_config.repetition = 0x00;
 timer_b_config.prescaler = HAL_HRTIM_TIM_PRESCALER_DIV4;
 timer_b_config.operating_mode = HAL_HRTIM_TIM_MODE_CONTINUOUS;
 HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMB, &timer_config);

 /* Set compare register 1 in Timer B */
 HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMB, HAL_HRTIM_COMPARE_UNIT_1, 0x100);

 /* Start HRTIM TIMER A in DMA mode and HRTIM TIMER B in polling mode*/
 HAL_HRTIM_TIM_Start_DMA(&hhrtim,  HAL_HRTIM_TIMA | HAL_HRTIM_TIMB);

Key changes

  • HAL2 links the DMA channel via HAL_HRTIM_SetDMA() and configures DMA requests via HAL_HRTIM_SetConfigDMA().

  • HAL2 uses dedicated event and filtering APIs (for example HAL_HRTIM_EVT_SetConfig() and HAL_HRTIM_TIM_SetEventFilter()).

  • HAL2 starts capture in DMA mode with HAL_HRTIM_TIM_Start_DMA() using explicit timer selection.